{% extends "base.html" %}
{% block subtitle -%}
{{ _('Submission Detail') }} - {% if hw %}{{ hw.info.name }}
                               {%- else %}{{ _('Homework Deleted') }}{% endif %}
{%- endblock %}
{% block content -%}
  <h3 class="detail-heading">
    {% if hw -%}
      {{ _('Submission for <a href="%(url)s">%(name)s</a>',
           url=url_for('homework', slug=hw.slug), name=hw.info.name) }}
    {%- else -%}
      {{ _('Submission for <span class="text-muted">(%(name)s)</a>', name=_('Deleted')) }}
    {%- endif %}
    <span class="label label-{{ handin.state | handinstyle }}">{{ handin.get_state() }}</span>
  </h3>

  {% if hw -%}
    {%- set code = hw.get_code(handin.lang) -%}
    {%- set reportCompile = code.reportCompile -%}
    {%- set reportRuntime = code.reportRuntime -%}
  {%- else -%}
    {%- set code = None -%}
    {%- set reportCompile = True -%}
    {%- set reportRuntime = False -%}
  {%- endif %}

  <!-- Summary panel -->
  <div class="panel panel-default detail-summary">
    <div class="panel-heading">{{ _('Summary') }}</div>
    <table class="table table-hover">
      <tr>
        <th style="width: 20%">{{ _('Upload user') }}</th>
        <td>{{ handin.user.name }}</td>
      </tr>
      <tr>
        <th style="width: 20%">{{ _('Upload time') }}</th>
        <td>{{ handin.ctime | datetimeformat }}</td>
      </tr>
      <tr>
        <th>{{ _('Submission Type') }}</th>
        <td>{{ handin.lang | codelang }}</td>
      </tr>
      {% if handin.is_accepted() -%}
        <tr>
          <th>{{ _('Base Score') }}</th>
          <td>
            <span style="color: {{ handin.score | scorecolor }}">{{ handin.score | roundscore }}</span>
          </td>
        </tr>
        <tr>
          <th>{{ _('Score Scale') }}</th>
          <td><span style="color: {{ handin.scale | scalecolor }}">{{ handin.scale }}</span></td>
        </tr>
        <tr>
          <th>{{ _('Final Score') }}</th>
          {%- set final_score = handin.score * handin.scale -%}
          <td><span style="color: {{ final_score | scorecolor }}">{{ final_score | roundscore }}</span></td>
        </tr>
      {%- else -%}
        <tr>
          <th>{{ _('Exit Code') }}</th>
          <td>
            {% if handin.exitcode is none -%}
              <span class="text-muted">{{ _('Not started') }}</span>
            {%- elif handin.exitcode != 0 -%}
              <span class="text-danger">{{ handin.exitcode }}</span>
            {%- else -%}
              <span class="text-success">{{ handin.exitcode }}</span>
            {%- endif %}
          </td>
        </tr>
      {%- endif %}
      <tr>
        <th>{{ _('Summary') }}</th>
        <td>
          {% if handin.result -%}
            {{ handin.result }}
          {%- else -%}
            <span class="text-muted">{{ _('No summary') }}</span>
          {%- endif %}
        </td>
      </tr>
    </table>
  </div>

  <!-- Compile message of the process -->
  {% if (reportCompile or current_user.is_admin) and handin.get_compile_error() -%}
  <div class="panel panel-default detail-compile">
    <div class="panel-heading">{{ _('Compilation Output') }}</div>
    <div class="panel-body">
      <pre>{{ handin.get_compile_error() }}</pre>
    </div>
  </div>
  {%- endif %}

  <!-- Standard output and Error output of the process -->
  {% if (reportRuntime or current_user.is_admin) and handin.get_stdout() -%}
    <div class="panel panel-default detail-stdout">
      <div class="panel-heading">{{ _('Standard Output') }}</div>
      <div class="panel-body">
        <pre>{{ handin.get_stdout() }}</pre>
      </div>
    </div>
  {%- endif %}
  {% if (reportRuntime or current_user.is_admin) and handin.get_stderr() -%}
    <div class="panel panel-default detail-stderr">
      <div class="panel-heading">{{ _('Standard Error Output') }}</div>
      <div class="panel-body">
        <pre>{{ handin.get_stderr() }}</pre>
      </div>
    </div>
  {%- endif %}

  <!-- Report from each partial scorer -->
  {% if handin.partials -%}
  {% for p in handin.partials %}
    {# determine whether or not to report details #}
    {% if code -%}
      {%- set scorer_cfg = code.get_scorer(p.typeName) -%}
      {%- if scorer_cfg -%}
        {%- set reportDetail = scorer_cfg.detail -%}
      {%- else -%}
        {%- set reportDetail = None -%}
      {%- endif -%}
    {%- else -%}
      {%- set reportDetail = None -%}
    {%- endif %}
    {% if reportDetail is none -%}
      {%- set reportDetail = reportRuntime -%}
    {%- endif %}
    <div class="panel panel-default detail-partial">
      <div class="panel-heading">{{ p.name }}</div>
      <table class="table table-hover">
        <tr>
          <th style="width: 20%">{{ _('Score') }}</th>
          <td>
            <span style="color: {{ p.score | scorecolor }}">{{ p.score | roundscore }}</span>
          </td>
        </tr>
        <tr>
          <th>{{ _('Weight') }}</th>
          <td>{{ p.weight }}</td>
        </tr>
        <tr>
          <th>{{ _('Run time') }}</th>
          <td>
            {% if p.time -%}
              {{ p.time | timedeltaformat }}
            {%- else -%}
              <span class="text-muted">{{ _('Not measured') }}</span>
            {%- endif %}
          </td>
        </tr>
        <tr>
          <th>{{ _('Summary') }}</th>
          <td>
            {% if p.brief -%}
              {{ p.brief }}
            {%- else -%}
              <span class="text-muted">{{ _('No summary') }}</span>
            {%- endif %}
          </td>
        </tr>
        {% if (reportDetail or current_user.is_admin) and p.detail -%}
          <tr>
            <th>{{ _('Details') }}</th>
            <td>
              {{ renderPartialScore(p) | safe }}
            </td>
          </tr>
        {%- endif %}
      </table>
    </div>
  {% endfor %}
  {%- endif %}

{%- endblock %}